/*----The timer class--------
	To start timer write: var timer = new Timer(max_time, function() {myClass.Finish();});
	Finish() executes as soon as timer stops. If Finish() belongs to another class
	you can't write like this var timer = new Timer(max_time, myClass.Finish(););
	because in this case only the text of function will be sent and class' variables'll
	be undefined. Also timer class should be just after window object because of
	using window.setTimeout("timer_class.tick()", 1000); function
*/
var timer_class;

function Timer(max_time, OnTimerOver) {
	this.counter = max_time;
	timer_class = this;
	this.OnTimerOver = OnTimerOver;
	this.tick();
}

Timer.prototype = {
	tick: function() {
		if (timer_class.counter != 0) {
			timer_class.counter -= 1;
			window.setTimeout("timer_class.tick()", 1000);		
		}
		else {
			timer_class.OnTimerOver();
		}
	},
	timerOut: function() {
		return this.counter;
	}
}

//--------------End timer--------------

function Finish() {
	alert("end");
}

function Start() {
	var timer = new Timer(1, function() {Finish();}, function() {Finish();});
	alert(timer.timerOut());
}
